app.fight = {
	init : function() {
		$(app).bind({
			'fightinit' : function(event, enemyType) {
				app.FightMgr.startFight(enemyType);
			}
		});
	}
};

app.FightMgr = {
	startFight : function(enemyType) {
		var enemy = app.UnitMgr.createUnit(type);
		var s1, s2, that = this;
		
		if (Math.random() <= .5) {
			s1 = this._player;
			s2 = enemy;
		}
		else {
			s1 = enemy;
			s2 = this._player;
		}
		
		this.clearLog();
		this.log(s1.name + ' attacks ' + s2.name + '!');
		
		do {
			var damage = s1.getDamage();
			
			s2.health -= damage;
			this.log(s1.name + ' hits ' + s2.name + ' for ' + damage + ' damage!');
			
			if (s2.isDead()) {
				this.log(s2.name + ' dies');
				break;
			}
			
			var tmp = s1;
			s1 = s2;
			s2 = tmp;
		} while (true);
		
		this.toggleStage();
		this._log.fadeIn('fast').delay(2000).fadeOut('slow', function() {
			that.toggleStage();
		});
		
		return true;
	}
};